package com.example.bailin.giftsay.sort.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.baseclass.BaseActivity;
import com.example.bailin.giftsay.entity.SortColumnEntity;
import com.example.bailin.giftsay.sort.LmClickListener;
import com.example.bailin.giftsay.sort.adapter.SortColumnAdapter;
import com.example.bailin.giftsay.tool.MyApp;
import com.example.bailin.giftsay.tool.NetTool;
import com.example.bailin.giftsay.tool.UrlProvide;

/**
 * Created by bailin on 16/8/19.
 * <p/>
 * 栏目点击查看全部跳转的Activity
 */
public class SoryColumnActivity extends BaseActivity implements View.OnClickListener, LmClickListener {

    private ListView lv;

    @Override
    protected int setLayout() {
        return R.layout.activity_sortcolumn;
    }

    @Override
    protected void initView() {
        lv = bindView(R.id.lv_sortcolumn);
        ImageView iv = bindView(R.id.iv_sorycolumn_return);
        iv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        finish();
    }

    @Override
    protected void initData() {
        tool().getData(UrlProvide.SORT_STRATEGY_COLUMN, SortColumnEntity.class, new NetTool.NetInterface<SortColumnEntity>() {
            @Override
            public void onSuccess(SortColumnEntity sortColumnEntity) {
                SortColumnAdapter adapter = new SortColumnAdapter();
                adapter.setEntity(sortColumnEntity);
                adapter.setLmClickListener(SoryColumnActivity.this);
                lv.setAdapter(adapter);
            }

            @Override
            public void onError(String errorMsg) {
            }
        });
    }

    @Override
    public void onClick(int id, String title) {
        Intent intent = new Intent(MyApp.getContext(), LmSkipActivity.class);
        intent.putExtra("id", id);
        intent.putExtra("title", title);
        startActivity(intent);
    }
}